<extend name="Layout/ins_page" />

<block name="content">
		{:W('PageHeader/simple',array('name'=>'请假','search'=>'N'))}
	<div class="operate panel panel-default">
		<div class="panel-body">
			<div class="pull-left">
				<a onclick="go_return_url();" class="btn btn-sm btn-primary">返回</a>
				<eq name="flow_type.is_lock" value="0">
					<a onclick="popup_confirm();"  class="btn btn-sm btn-primary">选择审批流程</a>
				</eq>
			</div>
			<div class="pull-right">

				<a onclick="save(20);"  id="post" class="btn btn-sm btn-primary">提交申请</a>
			</div>
		</div>
	</div>
	<form method='post' id="form_data" name="form_data" enctype="multipart/form-data" class="well form-horizontal">
		<input type="hidden" id="id" name="id" value="<?php echo $leave['id']?>" >
	    <input type="hidden" id="confirm" name="confirm" value="<?php echo $leave['confirm']?>" >
		<input type="hidden" id="confirm_name" name="confirm_name" value='<?php echo $leave['confirm_name']?>' >

		<div class="form-group">
			<label class="col-sm-2 control-label" for="name">请假类型：</label>			
			<div class="col-sm-10">
				<select class="form-control" id='type' name = 'type'>
				<?php foreach($typelist as $type){?>
				<option  <?php if($type['key']==$leave['type']){echo "selected='selected'";}?> value="<?php echo $type['key']?>"><?php echo $type['value']?></option>
				<?php };?>
				</select>
			</div>
		</div>
		<div class="form-group col-xs-12">
			<label class="col-sm-2 control-label" for="type">审批步骤：</label>
			<div class="col-sm-10">
				<div id="confirm_wrap" class="inputbox">
					<a class="pull-right btn btn-link text-center" onclick="popup_flow();"> <i class="fa fa-user"></i> </a>
					<div class="wrap" >
						<span class="address_list"><?php echo $leave['confirm_name']?></span>
						<span class="text" >
							<input class="letter" type="text"  >
							
						</span>
						
					</div>
					<div class="search dropdown ">
						<ul class="dropdown-menu"></ul>
					</div>
				</div>
			</div>
		</div>
		
	
		

			<div class="form-group">
			<label class="col-sm-2 control-label" for="name">请假时间：</label>			
			<div class="col-sm-10">
			<input type="text" value="<?php echo date('Y-m-d H:i:s',$leave['start_time'])?>" style='width: 200px;float: left'  id="start_time" name="start_time" readonly="readonly" class="form-control input-date-ymd-h changge-h" check="require" msg="请输入开始日期">
			<span style="float: left;;margin: 10px">至</span>
			<input value="<?php echo date('Y-m-d H:i:s',$leave['end_time'])?>" style='width: 200px;float: left' type="text" id="end_time" name="end_time" readonly="readonly" class="form-control input-date-ymd-h changge-h" check="require" msg="请输入结束日期" readonly="readonly">					
			</div>
		</div>
		
		
		<div class="form-group">
			<label class="col-sm-2 control-label" for="name">复工时间：</label>			
			<div class="col-sm-10">
			<input value="<?php echo date('Y-m-d H:i:s',$leave['comeback_time'])?>"  type="text" style='width: 200px;float: left'  id="comeback_time" name=" comeback_time" readonly="readonly" class="form-control input-date-ymd-h" check="require" msg="请输入复工日期">				
			</div>
		</div>
		
			<div class="form-group">
			<label class="col-sm-2 control-label" for="name">总时(小时)：</label>			
			<div class="col-sm-10">
				<input class="form-control" type="text" id="count_time_h" value="<?php echo $leave['count_time_h']?>" name="count_time_h">
			</div>
		</div>
		
		<div class="form-group" id='deductions_day_div'>
			<label class="col-sm-2 control-label" for="name">扣除工资(天)：</label>			
			<div class="col-sm-10">
				<input class="form-control" type="text" id="deductions_day" name="deductions_day"  value="<?php echo $leave['deductions_day']?>" >
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-2 control-label" for="name">请假事由：</label>			
			<div class="col-sm-10">
				<textarea  class="editor" id="content" name="content" style="width:100%;height:300px;"><?php echo $leave['udf_data']?></textarea>
			</div>
		</div>
			
		

	</form>
</block>
<block name="js">
<script>
$('#type').change(function(){
	var value = parseInt( $(this).val());
	if(value>0){
		$('#deductions_day_div').hide();
	}else{
		$('#deductions_day_div').show();
	}
	
});
function popup_flow() {
	winopen("{:U('popup/flow')}",560, 470);
};

$(document).ready(function() {
$('.input-date-ymd-h').datetimepicker({
	format : 'YYYY-MM-DD H:00:00',
	locale : 'zh-cn',
	ignoreReadonly : true,
	widgetPositioning : {
		horizontal : 'auto',
		vertical : 'bottom'
	},
});


});


function save(step) {
	$("#confirm").val("");
	$("#confirm_wrap  span.address_list span").each(function() {
		$("#confirm").val($("#confirm").val() + $(this).attr("data") + '|');
	});

	$("#confirm_name").val("");
	$("#confirm_name").val($("#confirm_wrap span.address_list").html());

	if ($("#comeback_time").val().length < 2) {
		ui_error('请选择复工日期');
		return false;
	}
	$("#step").val(step);
	sendForm("form_data", "{:U('saveleave')}", "{:U('index')}");
    var t=5;
	var int=setInterval(function(){
		t--;
		if(t==0){
			$("#post").html("提交申请")
			$("#post").attr("onclick","save(20)");
			 clearInterval(int);

		}else{
		  $("#post").attr("onclick","javascript:alert('不能重复提交！')");
		  $("#post").html("重新提交("+t+")")	
		}
	},1000)
	
}



$('.changge-h1').focus(function(){
	var changeObj = $('.changge-h');
	var v1 = $(changeObj[0]).val();
	var v2 = $(changeObj[1]).val();
	getD(v1,v2);
})

function getD(d1,d2){
	alert(d1+d2);
	var date1=new Date(d1);  //开始时间

	var date2=new Date(d2);    //结束时间
	var date3=date2.getTime()-date1.getTime()  //时间差的毫秒数
	 

	//计算出相差天数
	var days=Math.floor(date3/(24*3600*1000))
	 
	//计算出小时数

	var leave1=date3%(24*3600*1000)    //计算天数后剩余的毫秒数
	var hours=Math.floor(leave1/(3600*1000))

	$('#count_time_h').val(hours);
	
	}
</script>



</block>